package com.example.iread.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.iread.R;
import com.example.iread.adapter.BookListAdapter;
import com.example.iread.application.MyApplication;
import com.example.iread.bean.BookBean;
import com.example.iread.dao.BookDao;

import java.util.List;

public class BookHistoryActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_book_history);

        findViewById(R.id.btn_book_history_close).setOnClickListener(v -> finish());

        TextView tv_empty = findViewById(R.id.tv_empty);
        RecyclerView rv_book_history = findViewById(R.id.rv_book_history);

        BookDao bookDao = MyApplication.getInstance().getDb().bookDao();
        List<BookBean> list = bookDao.getList();

        if (list == null || list.size() == 0) return;

        tv_empty.setVisibility(View.GONE);
        rv_book_history.setVisibility(View.VISIBLE);

        rv_book_history.setLayoutManager(new LinearLayoutManager(this));
        BookListAdapter bookListAdapter = new BookListAdapter(this, list);
        rv_book_history.setAdapter(bookListAdapter);
    }
}